package jul;

import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class LogTest {
    public static void main(String[] args) throws IOException {
        Logger logger = Logger.getLogger(LogTest.class.getName());
        logger.setLevel(Level.ALL);
        logger.setUseParentHandlers(false);

        ConsoleHandler handler = new ConsoleHandler();
        handler.setLevel(Level.ALL);
        logger.addHandler(handler);

        FileHandler fileHandler = new FileHandler("test.log");
        fileHandler.setLevel(Level.WARNING);
        logger.addHandler(fileHandler);

        logger.log(Level.SEVERE, "严重的错误", new IOException("我就是错误"));
        logger.log(Level.WARNING, "警告的内容");
        logger.log(Level.INFO, "普通的信息");
        logger.log(Level.CONFIG, "级别低于普通信息");
    }
}
